package me.whf.dao;

import java.util.ArrayList;

import me.whf.model.Employee;
import me.whf.util.Utils;
import me.whf.util.Utils.EmployeeType;

public class FileEmployeeDAO implements EmployeeDAO {
	
	public boolean isExisted(String employeeID) {
		return Utils.employees.containsKey(employeeID);
	}
	
	public boolean register(String employeeID, String password, String username, String apartmentID, EmployeeType employeeType) {
		Employee employee = new Employee(employeeID, password, username, apartmentID, employeeType);
		Utils.employees.put(employeeID, employee);
		
		ArrayList<String> department = Utils.apartments.get(apartmentID);
		if (department == null) {
			ArrayList<String> temp = new ArrayList<String>();
			temp.add(employeeID);
			Utils.apartments.put(apartmentID, temp);
		} else {
			department.add(employeeID);
			Utils.apartments.put(apartmentID, department);
		}
		
		return true;
	}
	
	// return  apartment id
	public Employee login(String employeeID, String password) {
		Employee employee = Utils.employees.get(employeeID);
		
		if (employee != null && employee.getPassword().equals(password)) {
			return employee;
		} else {
			return null;
		}
	}
}
